package org.linlinjava.litemall.db.service;

import java.time.LocalDateTime;
import java.util.List;

import javax.annotation.Resource;

import org.linlinjava.litemall.db.dao.LitemallGoodsPropertyMapper;
import org.linlinjava.litemall.db.domain.LitemallGoodsProperty;
import org.linlinjava.litemall.db.domain.LitemallGoodsPropertyExample;
import org.springframework.stereotype.Service;

/**
 * @author ：lilu
 */
@Service
public class LitemallGoodsPropertyService {
	
    @Resource
    private LitemallGoodsPropertyMapper litemallGoodsPropertyMapper;

    public LitemallGoodsProperty findById(Integer id) {
        return litemallGoodsPropertyMapper.selectByPrimaryKey(id);
    }

    public int add(LitemallGoodsProperty record){
        record.setAddTime(LocalDateTime.now());
        record.setUpdateTime(LocalDateTime.now());
        return litemallGoodsPropertyMapper.insertSelective(record);
    }

    public int update(LitemallGoodsProperty record){
    	record.setUpdateTime(LocalDateTime.now());
        return litemallGoodsPropertyMapper.updateByPrimaryKeySelective(record);
    }


    public int deleteById(Integer id) {
        return litemallGoodsPropertyMapper.deleteByPrimaryKey(id);
    }
    

    public List<LitemallGoodsProperty> queryByGoodsId(Integer goodsId){
    	LitemallGoodsPropertyExample example = new LitemallGoodsPropertyExample();
    	example.or().andGoodsIdEqualTo(goodsId).andDeletedEqualTo(false);
    	example.setOrderByClause("sort asc,add_time desc");
    	
    	return litemallGoodsPropertyMapper.selectByExample(example);
    }
    
}
